// reference: https://www.cnblogs.com/damonFeng/archive/2018/01/30/8378123.html
export function getElementPosition (el) {
  let actualTop = el.offsetTop
  let current = el.offsetParent
  while (current !== null) {
    actualTop += current.offsetTop
    current = current.offsetParent
  }
  return actualTop
}

export function copyText (text) {
  let succeeded
  const container = document.body
  const el = document.createElement('textarea')
  el.value = text
  el.setAttribute('readonly', '')
  el.style.position = 'absolute'
  el.style.left = '-9999px'
  el.style.opacity = 0
  container.appendChild(el)
  el.select()
  try {
    succeeded = document.execCommand('copy')
  } catch (err) {
    succeeded = false
  }
  container.removeChild(el)
  return succeeded
}
